package com.kalua.list.harvester.parser;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Maps;
import com.kalua.list.domainmodel.NumericId;
import com.kalua.list.domainmodel.TextIdentifier;

public class ProductParseFunctionFactoryImpl implements ProductParseFunctionFactory {
	
	private Map<TextIdentifier, ProductParseFunction> prototypes;
	
	public ProductParseFunctionFactoryImpl(List<ProductParseFunction> parseFunctions) { 
		this.prototypes = Maps.newHashMap();
		for (ProductParseFunction productParseFunction : parseFunctions) 
			this.prototypes.put(	productParseFunction.getRetailerId(), 
											productParseFunction);
	}
	
	@Override
	public ProductParseFunction 
							createParseFunction( TextIdentifier retailerId, 
															NumericId batchId) {
		ProductParseFunction result;
		ProductParseFunction prototype = 
				this.prototypes.get(retailerId);		
		result = prototype.fromPrototype(batchId);
		return result;
	}
}